<template>
    <div class="tab-bar-item" @click="changeView" :style="activeStyle">
       <slot name="tabitem-icon"></slot>
       <slot name="tabitem-text"></slot>
    </div>
</template>
<script>
export default {
    name:'TabBarItem',
    props:{
        viewSrc:{
            type:String
        }
    },
    methods:{
        changeView(){
            this.$router.replace(this.viewSrc);
        }
    },
    computed:{
        // 判断当前活跃的路由是不是当前组件的功能路由
        isActive(){
            return this.$route.path==this.viewSrc;
        },
        activeStyle(){
            // 从计算属性得知当前活跃的路由是不是当前组件的功能路由
            // 是的话就将当前活跃的路由变成粉色
            return this.isActive?{color:'deeppink'}:{}
        }
    }
}
</script>
<style scoped>
.tab-bar-item{
  flex: 1;
  text-align: center;
  height: 49px;
  font-size: 14px;
}
.tab-bar-item img{
  width: 24px;
  height: 24px;
  margin-top: 3px;
  vertical-align: middle 
}
</style>